var t = getApp();

Page({
    data: {
        active: 0,
        url: "",
        projectList: [],
        title: "已预约项目",
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        this.init(), this.getData();
    },
    selectTab: function(t) {
        console.log(t);
        var a = t.detail.index;
        this.setData({
            active: 2 != a ? a : 9
        }), this.getData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var t = this.data.page + 1;
            this.getMoreData(t);
        }
    },
    onShareAppMessage: function() {},
    init: function() {
        this.page = 1, this.isLoadMore = !0, this.total_page = 0, this.projectList = [], 
        this.setData({
            page: 1,
            isLoadMore: !0,
            total_page: 0,
            projectList: [],
            appointmentLang: wx.getStorageSync("yz_basic_info").lang.appointment
        }), "store" === this.options.name ? this.setData({
            title: "门店预约",
            url: "plugin.appointment.frontend.appointment-service.get-list-by-store"
        }) : this.setData({
            title: this.data.appointmentLang.worker + "预约",
            url: "plugin.appointment.frontend.appointment-service.get-list-by-worker"
        }), wx.setNavigationBarTitle({
            title: this.data.title
        });
    },
    sure: function(t) {
        var a = this, e = t.currentTarget.dataset.id;
        wx.showModal({
            title: "您确定要取消此预约吗?",
            success: function(t) {
                t.confirm && a.cancelDate(e);
            }
        });
    },
    cancelDate: function(a) {
        var e = this, i = t.getNetAddresss("plugin.appointment.frontend.appointment-service.cancel-service");
        t._getNetWork({
            url: i,
            data: {
                id: a
            },
            success: function(a) {
                var i = a.data;
                1 == i.result ? (t.tips(i.msg), e.getData()) : wx.showToast({
                    title: i.msg,
                    icon: "none"
                });
            }
        });
    },
    getData: function() {
        this.init();
        var a = this, e = t.getNetAddresss(this.data.url);
        t._getNetWork({
            url: e,
            data: {
                status: a.data.active,
                page: a.data.page
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? (console.log(e), a.setData({
                    projectList: e.data.data,
                    current_page: e.data.current_page,
                    last_page: e.data.last_page
                })) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            }
        });
    },
    getMoreData: function(a) {
        var e = this, i = this, n = t.getNetAddresss(this.data.url);
        t._getNetWork({
            url: n,
            data: {
                status: i.data.active,
                page: a
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? i.setData({
                    projectList: e.data.projectList.concat(a.data.data),
                    current_page: a.data.current_page,
                    last_page: a.data.last_page
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            }
        });
    }
});